﻿//var apiUrl = "http://localhost:56713/";
var apiUrl = "http://twodogs.top:8020/";
var qqAppid = "101417839";
var qqRedirecturi = "http://www.twodogs.top/qqlogin.html";
var username, userfigure;
var $, layer, element;
layui.use(['layer', 'element', 'laypage'], function() {
	$ = layui.jquery;
	layer = layui.layer;
	element = layui.element;
	if(QC.Login.check()) {
		var paras = {};
		QC.api("get_user_info", paras)
			//指定接口访问成功的接收函数，s为成功返回Response对象
			.success(function(s) {
				username = s.data.nickname;
				userfigure = s.data.figureurl_1;
				$("#imgava").attr("src", userfigure);
				$("#ctnickname").text(username);
				$("#joy-loginout").show();
				$("#joy-login").hide();
			})
			//指定接口访问失败的接收函数，f为失败返回Response对象
			.error(function(f) {
				//失败回调
				layer.msg("获取用户信息失败！");
			})
			//指定接口完成请求后的接收函数，c为完成请求返回Response对象
			.complete(function(c) {

			});

	} else {

	}

	$("#joy-login").click(function() {
		QC.Login({}, function(data, ops) {
			username = data.nickname;
			userfigure = data.figureurl_1;
			$("#imgava").attr("src",userfigure);
			$("#ctnickname").text(username);
			$("#joy-loginout").show();
			$("#joy-login").hide();
		});
		QC.Login.showPopup({
			appId: qqAppid,
			redirectURI: qqRedirecturi
		});

	});
	$("#joy-loginout").click(function() {
		QC.Login.signOut();
		$("#joy-loginout").hide();
		$("#joy-login").show();
	});

});

//获取url中的参数
function getUrlParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg); //匹配目标参数
	if(r != null) return unescape(r[2]);
	return null; //返回参数值
}


function errorImg(img) {
	img.src = "images/helloworld.png"
	img.onerror = null;
}

function errorFigure(img) {
	img.src = "images/touxiang.jpg"
	img.onerror = null;
}

function errorLink(img) {
	img.src = "images/friendlink.png"
	img.onerror = null;
}


function getarticletype(id) {
	switch(id) {
		case 0:
			return "默认分类";
			break;
		case 10:
			return "Android";
			break;
		case 11:
			return "IOS";
			break;
		case 12:
			return "Java";
			break;
		case 13:
			return "C#";
			break;
		case 14:
			return "Web前端";
			break;
		case 15:
			return "html5";
			break;
		case 16:
			return "数据库";
			break;
		case 99:
			return "闲情随笔";
			break;
		default:
			return "默认分类";
			break;

	}
}

function getrestype(id) {
	switch(id) {
		case 0:
			return "默认分类";
			break;
		case 1:
			return "源码";
			break;
		case 2:
			return "文档";
			break;
		default:
			return "默认分类";
			break;

	}
}
//获取热门文章
function GetTopArticleList() {
	$.ajax({
		url: apiUrl + 'api/Web/GetTopArticleList',
		type: 'get', //GET
		async: true, //或false,是否异步
		dataType: 'json',
		success: function(jsondata) {
			if(jsondata.Type == 1) {
				$("#dlTopArticle").html("").append('<dt class="fly-panel-title">热门文章</dt>');
				$.each(jsondata.Data, function(index, item) {
					$("#dlTopArticle").append('<dd><a href="articledetail.html?id=' + item.Id + '"><i class="fa fa-thumbs-up"></i>' + item.Articlename + '</a></dd>');
				});

			}
		},
		error: function(xhr, textStatus) {

		},
		complete: function() {

		}
	});

}

//获取最新资源
function GetTopResourceList() {
	$.ajax({
		url: apiUrl + 'api/Web/GetTopResourceList',
		type: 'get', //GET
		async: true, //或false,是否异步
		dataType: 'json',
		success: function(jsondata) {
			if(jsondata.Type == 1) {
				$("#dlTopResource").html("").append('<dt class="fly-panel-title">最新资源</dt>');
				$.each(jsondata.Data, function(index, item) {
					$("#dlTopResource").append('<dd><a href="' + item.Re_downloadurl + '"><i class="fa fa-share"></i>' + item.Re_name + '</a></dd>');
				});

			}
		},
		error: function(xhr, textStatus) {

		},
		complete: function() {

		}
	});

}

//获取今日福利
function GetOneFuli() {
	$.ajax({
		url: apiUrl + 'api/Web/GetOneFuli',
		type: 'get', //GET
		async: true, //或false,是否异步
		dataType: 'json',
		success: function(jsondata) {
			if(jsondata.Type == 1) {
				$("#dlFuli").html("").append('<dt class="fly-panel-title">今日福利</dt>').append('<dd><a href="fulidetail.html?id=' + jsondata.Data.Id + '"><i class="fa fa-heart"></i>' + jsondata.Data.Title + '</a></dd>');
			}
		},
		error: function(xhr, textStatus) {

		},
		complete: function() {

		}
	});

}

//获取广告
function GetAdv() {
	$("#divAdv").html("");	
	$("#divAdv").append('<a href="https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=dlf1zzfd&utm_source=dlf1zzfd" target="_blank" class="fly-zanzhu" time-limit="2017.09.25-2099.01.01" style="background-color: #5FB878;">阿里云幸运券无私奉上</a>');
	$("#divAdv").append('<a href="https://originss.org/auth/register?code=3013" target="_blank" class="fly-zanzhu" time-limit="2017.09.25-2099.01.01" style="background-color: #f4516c;">墙外的世界很精彩</a>');
}